package ru.urfc.portal.ui.client.googlets.client;

import ru.urfc.portal.ui.client.BaseGooglet;
import ru.urfc.portal.ui.client.Style;
import ru.urfc.portal.ui.client.descriptor.GridDescriptor;
import ru.urfc.portal.ui.client.model.catalogs.InvoiceState;
import ru.urfc.portal.ui.client.renderers.MoneyTextRenderer;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Widget;

public class InvoiceInfo extends BaseGooglet {

	interface Binder extends UiBinder<Widget, InvoiceInfo> {}
	private static Binder binder = GWT.create(Binder.class);
	
	@UiField Style style;
	@UiField Element number;
	@UiField Element date;
	@UiField Element contractNumber;
	@UiField Element contractIssueDate;	
	@UiField Element state;
	@UiField Element name;
	@UiField Element amount;
	@UiField Element amountNds;
	@UiField Element amountTotal;
	@UiField Element amountTotal2;
	@UiField Element amountTotal3;
	
	@UiHandler("print")
	void print(ClickEvent e) {
	}
	
	@Override
	protected void init() {
		initWidget(binder.createAndBindUi(this));
		
		GridDescriptor descriptor = new GridDescriptor(INVOICE, CLIENTS, getClientId(), INVOICES, getItemId());
		descriptor.addTextField("number", number);
		descriptor.addDateField("date", date);

		descriptor.addTextField("contract/number", contractNumber);
		descriptor.addDateField("contract/issueDate", contractIssueDate);
		
		descriptor.addBoolCIField("isPaid", InvoiceState.class, state, style);
		descriptor.addTextField("name", name);
		descriptor.addMoneyField("amount", amount);
		descriptor.addMoneyField("amountNds", amountNds);
		descriptor.addMoneyField("amountTotal", amountTotal);
		descriptor.addMoneyField("amountTotal", amountTotal2);		
		descriptor.assign(new MoneyTextRenderer(descriptor.addField("amountTotal", Double.class), amountTotal3));
		createController(descriptor);

		createPrintAction();
	}

	private void createPrintAction() {
		new GridDescriptor(INVOICE, CLIENTS, getClientId(), INVOICES, getItemId(), INVOICE_PRINT);
	}

}